#!/usr/bin/env sh
set -e

cd docs/_posts
read -p "请输入文章名，以回车结束：" title
if [ ! "$title" ]; then
title="new-$(date "+%Y-%m-%d")"
fi
echo "---
title: $title
date: $(date "+%Y-%m-%d %H:%M:%S")
tags: 
author: $(whoami)
location: 
layout: Post
summary: 
---" > "$title.md"
echo "已在/docs/_posts下生成$title.md，"
read -p "下一步将 （1.打开文件夹 2.使用vscode编辑该文件），以回车结束：" action
if [ $action == 1 ]
then
explorer .
else
code "$title.md"
fi
cd -